<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <link href="../css/element.css" rel="stylesheet"/>
    <link href="../css/styleindex.css" rel="stylesheet"/>
    <style>
    .x-a .el-input__inner,.x-a .el-textarea__inner{
      border: 1px solid #ccc;
    }.x-a .el-textarea__inner{
      background-color: #f5f7fa
    }
    </style>
</head>
<body style="background:#EFF0F4;">

  <div class="mui-content">
    <div id="vm" class="x-examok" v-cloak>
      <!--  -->
      <div class="x-pro-list">
        <div class="x-pro-top">计划目标</div>
        <div class="x-pro-row">
          <div class="x-pro-label">计划销售额:</div>
          <div class="x-pro-input">
            {{planmoney}}
          </div>
        </div>
        <div class="x-pro-row">
          <div class="x-pro-label">预估销售额:</div>
          <div class="x-pro-input">
            {{ifmoney}}
          </div>
        </div>
        <div class="x-pro-row">
          <div class="x-pro-label">实际销售额:</div>
          <div class="x-pro-input x-a">
            <el-input placeholder="请输入" v-model="nowmoney" :disabled="isfromindex" type="number"></el-input>
          </div>
        </div>

        <div v-for="(item,index) in othermoney" :key="item.key" class="x-for-border">
          <div class="x-pro-row x-pro-rowblock">
            <div class="x-pro-label">其他销售目标{{index+1}}:{{item.content}}</div>
            <!-- <div class="x-for-border">
              <div class="x-pro-input">

              </div>
            </div> -->
          </div>
          <div class="x-pro-row x-pro-rowblock">
            <div class="x-pro-label">完成结果</div>
            <div class="x-pro-input x-a">
              <el-input placeholder="请输入" v-model="item.effect" :disabled="isfromindex" type="textarea" :rows="3"></el-input>
            </div>
          </div>
        </div>


      </div>
      <!--  -->
      <div class="x-pro-list">
        <div class="x-pro-top">追踪工作</div>
        <template>
          <el-table :data="tabledata">
            <el-table-column label="序号" width="50" type="index" fixed></el-table-column>
            <el-table-column label="工作名称" width="" fixed>
              <template slot-scope="scope">
                {{scope.row.title}}
              </template>
            </el-table-column>
            <el-table-column label="达成结果" width="">
              <template slot-scope="scope">
                {{scope.row.effect}}
              </template>
            </el-table-column>
            <el-table-column label="有无改善" width="120">
              <template slot-scope="scope">
                <el-button type="primary" v-if="scope.row.is_ok=='0'" @click="workok(scope.row.id,scope.row.title)" size="mini">点击确认</el-button>
                <div v-if="scope.row.is_ok=='1'" size="mini" class="x-text-g">已改善</div>
                <div v-if="scope.row.is_ok=='2'" size="mini" class="x-text-r">未改善</div>
              </template>
            </el-table-column>
          </el-table>
        </template>
      </div>
      <!-- 待办任务 -->
      <div class="x-pro-list">
        <div class="x-pro-top">待办任务</div>
        <template>
          <el-table :data="tabledatatwo">
            <el-table-column label="序号" width="50" type="index" fixed></el-table-column>
            <el-table-column label="优先级" width="" fixed>
              <template slot-scope="scope">
                {{scope.row.level}}
              </template>
            </el-table-column>
            <el-table-column label="任务名称" width="">
              <template slot-scope="scope">
                {{scope.row.title}}
              </template>
            </el-table-column>
            <el-table-column label="责任人" width="">
              <template slot-scope="scope">
                {{scope.row.memberid}}
              </template>
            </el-table-column>
            <el-table-column label="完成时间" width="">
              <template slot-scope="scope">
                {{scope.row.times}}
              </template>
            </el-table-column>
            <el-table-column label="是否完成" width="120">
              <template slot-scope="scope">
                <el-button type="primary" v-if="scope.row.is_ok=='0'" @click="workoktwo(scope.row.id,scope.row.title)" size="mini">点击确认</el-button>
                <div v-if="scope.row.is_ok=='1'" size="mini" class="x-text-g">已完成</div>
                <div v-if="scope.row.is_ok=='2'" size="mini" class="x-text-r">未完成</div>
              </template>
            </el-table-column>
          </el-table>
        </template>
      </div>
      <!--  -->
      <div class="x-pro-gobtn" @click="isok" v-show="!isfromindex">提交</div>
    </div>
  </div>

  <script type="text/javascript" src="../script/vue.js"></script>
  <script type="text/javascript" src="../script/element.js"></script>
  <script type="text/javascript" src="../script/api.js"></script>
  <script type="text/javascript" src="../script/base.js"></script>
	<script>
apiready = function () {
    $api.fixStatusBar($api.byId('header'));


    //
    var vm = new Vue({
      el:'#vm',
      data(){
        return{
          planmoney:'',
          isfromindex:false,
          ifmoney:'',
          nowmoney:'',
          tabledata:[],
          tabledatatwo:[],
          othermoney:[],
          finishpro:'',

        }
      },
      created:function() {
        var that=this;


      },
      mounted:function(){
        var that=this;
        that.getdata()//回显

      },
      methods: {
        //
        isok:function(){
          var that = this;
          console.log(that.nowmoney);
          console.log(JSON.stringify(that.othermoney));
          api.ajax({
            url:baseurl+'api/duty/summary',
            methods:'get',
            data:{
              values:{
                sec: $api.getStorage('apptoken'),
                real_sale:that.nowmoney,
                effect_json:that.othermoney
              }
            }
          },function(ret,err){
            if(ret){
              api.hideProgress();
              console.log(JSON.stringify(ret));
              if(ret.status == 1){
                api.confirm({
                    title: '提交成功',
                    msg: '',
                    buttons: ['继续编辑', '返回']
                }, function(ret, err) {
                    var index = ret.buttonIndex;
                    if(index=='1'){

                    }else{
                      api.closeWin({});

                    }
                });

              }else{
                api.toast({
                    msg: ret.msg,
                    duration: 3000,
                    location: 'bottom'
                });
              }
            }else{
              api.hideProgress();
              console.log(JSON.stringify(err));
              api.toast({
                  msg: err.msg,
                  duration: 3000,
                  location: 'bottom'
              });
            }
          })
        },
        //
        getdata:function(){
          let that=this;
          api.ajax({
            url:baseurl+'api/duty/content',
            methods:'get',
            data:{
              values:{
                sec: $api.getStorage('apptoken'),
                date:''
              }
            }
          },function(ret,err){
            if(ret){
              api.hideProgress();
              console.log(JSON.stringify(ret));
              if(ret.status == 1){
                  that.planmoney = ret.data.data.plan_sale;
                  that.ifmoney = ret.data.data.rate_sale;
                  if(ret.data.data.real_sale=='0'){
                    that.nowmoney = '';
                  }else{
                    that.nowmoney = ret.data.data.real_sale;
                  }
                  that.finishpro = ret.data.data.finish_content;
                  that.othermoney = ret.data.target;
                  that.tabledata = ret.data.follow;
                  that.tabledatatwo = ret.data.task;


              }else{
                api.toast({
                    msg: ret.msg,
                    duration: 3000,
                    location: 'bottom'
                });
              }
            }else{
              api.hideProgress();
              console.log(JSON.stringify(err));
              api.toast({
                  msg: err.msg,
                  duration: 3000,
                  location: 'bottom'
              });
            }
          })
        },
        //是否完成
        workoktwo:function(id,name){
          var that = this;
          api.actionSheet({
              title: '请确认“'+ name + '”是否完成',
              cancelTitle: '取消',
              buttons: ['已完成', '未完成']
          }, function(ret, err) {
              var index = ret.buttonIndex;
              if(index=='1'){
                that.settaketwo(id,index)
              }else if(index=='2'){
                that.settaketwo(id,index)
              }

          });
        },
        //是否完成 提交
        settaketwo:function(id,index){
          let that=this;
          api.ajax({
            url:baseurl+'api/duty/setTask',
            methods:'get',
            data:{
              values:{
                sec: $api.getStorage('apptoken'),
                id:id,
                type:index
              }
            }
          },function(ret,err){
            if(ret){
              api.hideProgress();
              console.log(JSON.stringify(ret));
              if(ret.status == 1){
                that.getdata()


              }else{
                api.toast({
                    msg: ret.msg,
                    duration: 3000,
                    location: 'bottom'
                });
              }
            }else{
              api.hideProgress();
              console.log(JSON.stringify(err));
              api.toast({
                  msg: err.msg,
                  duration: 3000,
                  location: 'bottom'
              });
            }
          })
        },
        //有无改善
        workok:function(id,name){
          var that = this;
          api.actionSheet({
              title: '请确认“'+ name + '”有无改善',
              cancelTitle: '取消',
              buttons: ['已改善', '未改善']
          }, function(ret, err) {
              var index = ret.buttonIndex;
              if(index=='1'){
                that.settake(id,index)
              }else if(index=='2'){
                that.settake(id,index)
              }

          });
        },
        //有无改善 提交
        settake:function(id,index){
          let that=this;
          api.ajax({
            url:baseurl+'api/duty/setFollow',
            methods:'get',
            data:{
              values:{
                sec: $api.getStorage('apptoken'),
                id:id,
                type:index
              }
            }
          },function(ret,err){
            if(ret){
              api.hideProgress();
              console.log(JSON.stringify(ret));
              if(ret.status == 1){
                that.getdata()


              }else{
                api.toast({
                    msg: ret.msg,
                    duration: 3000,
                    location: 'bottom'
                });
              }
            }else{
              api.hideProgress();
              console.log(JSON.stringify(err));
              api.toast({
                  msg: err.msg,
                  duration: 3000,
                  location: 'bottom'
              });
            }
          })
        },
      }
    })
	}


	</script>
</body>
</html>
